<template>
  <div>
    <div>
      <el-form :inline="true" :model="form">
        <el-button-group>
          <el-select v-model="form.userfrom" placeholder="请选择来源" style="width:150px;">
            <el-option label="微信" value="weixin"></el-option>
            <el-option label="微博" value="weibo"></el-option>
            <el-option label="QQ" value="QQ"></el-option>
            <el-option label="全部" value=""></el-option>
          </el-select>
          <el-input v-model="form.userName" clearable placeholder="姓名" style="width:150px;"/>
          <el-input v-model="form.phoneNumber" clearable placeholder="手机号" style="width:150px;"/>
          <el-input v-model="form.inviperson" clearable placeholder="邀请人姓名" style="width:150px;"/>
          <el-input v-model="form.inviphoneNumber" clearable placeholder="邀请人手机号" style="width:150px;"/>
          <el-form-item>
            <el-button type="primary" @click="_queryPictureByFileName">搜索</el-button>
          </el-form-item>
        </el-button-group>
      </el-form>
    </div>

    <el-table :data="getSysFiles" height="450" border :stripe="true" :highlight-current-row="true"
              @current-change="tableRowChangeClickHandler"
              style="width: 100%">
      <el-table-column type="index" label="序号" width='60'/>
      <el-table-column prop="externalClientId" label="客户编号" min-width="20%"/>
      <el-table-column prop="userName" label="用户姓名" min-width="20%"/>
      <el-table-column prop="userMobile" label="用户手机号" min-width="20%"/>
      <el-table-column prop="createDate" label="创建时间" min-width="20%"/>
      <el-table-column prop="userFrom" label="渠道" min-width="20%"/>
      <el-table-column prop="userInviterName" label="邀请人姓名" min-width="20%"/>
      <el-table-column prop="userInviterMobile" label="邀请人手机号" min-width="20%"/>
    </el-table>

    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="getSysFileCurrentPage"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="getFilesCount">
      </el-pagination>
    </div>

    <!--<upload-form ref="uploadForm" :mode="formMode" :param="currentRecord" @initdata="init"/>-->

  </div>
</template>

<script type="text/babel">
  import {mapActions} from 'vuex'

  import invitation from './bll/invitationStore'
  import store from '../../store'

  (!store.state.invitation) && store.registerModule('invitation', invitation)

  //  import VueQrcode from '../common/vueQRcode.vue';


  export default {
    data() {
      return {
        form: {
          userfrom: '',
          userName: '',
          phoneNumber: '',
          inviperson: '',
          inviphoneNumber: ''
        },
        formMode: null,
        currentRecord: null,
        pageSize: 10,
        //form: {},
        copyData: '',
        qrData: '',
        privFileUrlFlag: false,
        qrcode: {
          size: 120,
          level: 'L'
        }
      }
    },
    components: {},

    computed: {
      getSysFiles() {
        return this.$store.state.invitation.files;
      },
      getFilesCount() {
        return this.$store.state.invitation.totalCount;
      },
      getSysFileCurrentPage() {
        return this.$store.state.invitation.currentPage;
      }
    },

    mounted() {
      console.log('file upload page mounted.');
      this.initPage();
    },

    methods: {
      ...mapActions(['searchInviteCount', 'searchInvite', 'queryInvite', 'queryInviteCount']),

      initPage() {
        this.queryInvite();
        this.queryInviteCount();

      },

      init() {
        if (this.form.fileName === '') {
          this.queryInvite();
          this.queryInviteCount();
        }
//        this.searchInvite({fileName: this.form.fileName});
//        this.searchInviteCount({fileName: this.form.fileName})
        this.searchInvite({
          userName: this.form.userName,
          userfrom: this.form.userfrom,
          phoneNumber: this.form.phoneNumber,
          inviperson: this.form.inviperson,
          inviphoneNumber: this.form.inviphoneNumber,
          pageIndex: 1,
          pageSize: 10
        });
        this.searchInviteCount({
          userName: this.form.userName,
          userfrom: this.form.userfrom,
          phoneNumber: this.form.phoneNumber,
          inviperson: this.form.inviperson,
          inviphoneNumber: this.form.inviphoneNumber
        });

      },

      fileSpaceHandler() {
        this.showFileBucketDialog = true;
      },


      tableRowChangeClickHandler(currentRow, oldCurrentRow) {
        console.log(currentRow);
        this.currentRecord = currentRow;
//        this.$refs.uploadForm.disable();
      },

      handleSizeChange(val) {
        console.log(`每页 ${val} 条`)
        this.pageSize = val;
        if (this.form.fileName === '') {
          this.queryInvite({pageIndex: 1, pageSize: val});
        } else {
          //this.searchInvite({fileName: this.form.fileName, pageIndex: 1, pageSize: val});
          this.searchInvite({
            userName: this.form.userName,
            userfrom: this.form.userfrom,
            phoneNumber: this.form.phoneNumber,
            inviperson: this.form.inviperson,
            inviphoneNumber: this.form.inviphoneNumber,
            pageIndex: this.pageIndex,
            pageSize: val
          });

        }
      },
      handleCurrentChange(val) {
        console.log(arguments);
        console.log(`current${val}`);
        if (this.form.fileName === '') {
          this.queryPicture({pageIndex: val, pageSize: this.pageSize});
        } else {
          //this.searchInvite({fileName: this.form.fileName, pageIndex: val, pageSize: this.pageSize});
          this.searchInvite({
            userName: this.form.userName,
            userfrom: this.form.userfrom,
            phoneNumber: this.form.phoneNumber,
            inviperson: this.form.inviperson,
            inviphoneNumber: this.form.inviphoneNumber,
            pageIndex: val,
            pageSize: this.pageSize
          });

        }
      },
      formatterHandler(row, column) {
        switch (column.property) {
          case 'state':
            return row.state === 1 ? 'Yes' : 'Discard';
        }
      },
      _queryPictureByFileName() {
        console.log(this.form)
        this.searchInvite({
          userName: this.form.userName,
          userfrom: this.form.userfrom,
          phoneNumber: this.form.phoneNumber,
          inviperson: this.form.inviperson,
          inviphoneNumber: this.form.inviphoneNumber,
          pageSize: this.pageSize
        });
        this.searchInviteCount({
          userName: this.form.userName,
          userfrom: this.form.userfrom,
          phoneNumber: this.form.phoneNumber,
          inviperson: this.form.inviperson,
          inviphoneNumber: this.form.inviphoneNumber,
          pageSize: this.pageSize
        });
        //重置当前页
        this.getSysFileCurrentPage = 1;
      }
    }
  }
</script>

<style lang="scss">
  .download-url {
    padding: 5px;
  }

  .qrcode-wrapper {
    margin: auto;
  }
</style>

